import datetime

from App.ext import db
from App.models import BaseModel


# 蓝牙信标
class Ibeacon(BaseModel):
    __tabelename__ = "Ibeacons"
    __table_args__ = (
        db.UniqueConstraint(  # 联合唯一
            "major",
            "minor",
            name="ibeacon_unique"
        ),
    )
    major = db.Column(db.String(16))  # , name="楼号"
    minor = db.Column(db.String(16))  # , name="楼层"
    mac = db.Column(db.String(64), nullable=True)  # 设备的mac地址
    UUID = db.Column(db.String(64), nullable=True)  # 设备的uuid
    lat = db.Column(db.String(32), nullable=True)  # , name="设备安装的纬度"
    lng = db.Column(db.String(32), nullable=True)  # , name="设备安装的经度"
    time = db.Column(db.DateTime, default=datetime.datetime.now())  # , name="创建创建时间"


# 收集使用的用户
class Users(BaseModel):
    """
    用户表
        如果没有这个用户,就新建这个用户
    """
    mark = db.Column(db.String(64), index=True)


# 用户扫描到的设备
class UserCollectionIbeacon(BaseModel):
    __tablename__ = "user_collection_ibeacon"
    user_id = db.Column(db.Integer, db.ForeignKey("users.id"))
    col2user = db.relationship("Users", backref="user2col")

    terminal = db.Column(db.String(16))  # 来着那个终端
    major = db.Column(db.String(16))  # , name="楼号"
    minor = db.Column(db.String(16))  # , name="楼层"
    uuid = db.Column(db.String(64), nullable=True)  # 设备的uuid
    rssi = db.Column(db.Integer, nullable=True)  # 收到信标的强度
    time = db.Column(db.DateTime, default=datetime.datetime.now())  # , name="创建创建时间"




